package com.aaa.cs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.cs.entity.OperLog;
import com.aaa.cs.service.OperLogService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志记录(OperLog)表控制层
 *
 * @author makejava
 * @since 2020-12-03 08:39:01
 */
@RestController
@RequestMapping("operLog")
public class OperLogController {
    /**
     * 服务对象
     */
    @Resource
    private OperLogService operLogService;


    /**
     * 操作日志统计展示
     * @param yearMonth
     * @return
     */
    @GetMapping("operLogShowByMonth")
    public Result operLogShowByMonth(String yearMonth) {
        return operLogService.operLogShowByMonth(yearMonth);
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public OperLog selectOne(Integer id) {
        return this.operLogService.queryById(id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param operLog  实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody OperLog operLog) {
        //        System.out.println(operLog);
        return this.operLogService.queryAll(pageNo, pageSize, operLog);
    }

    /**
     * 根据ID删除
     *
     * @param operId id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer operId) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.operLogService.deleteById(operId));
    }

    /**
     * 更新
     *
     * @param @param operLog 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody OperLog operLog) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.operLogService.update(operLog));
    }

    /**
     * 添加
     *
     * @param @param operLog 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody OperLog operLog) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.operLogService.insert(operLog));
    }
}